<?php 
include('./fun.php');include('./hd_fun.php');
$conn=my_sql($cfg);
$re=user_login();
if($re['err']=='no_login'){direct('login.php?t='.time());exit;}
if($re['err']!='ok'){die($re['err']);}
$user=$re['user'];
$shop_id=$re['shop_id'];
$shop=get_shop();
$set=get_set();

$action=g('action');
if(!$action){$action='select_pro($(this))';}

$sql='select * from '.$cfg['e'].'pro where shop_id="'.$shop['id'].'" and state=1 ';
$c=g('c');
if($c){$sql.='and c=:c';$p['c']=$c;}

$page=g('page');
if(!$page){$page=1;}
$page_num=40;
$start=($page-1)*$page_num;
$sql.=' order by id desc limit '.$start.','.$page_num;

$l=db($sql,$p);
$sql='select c from '.$cfg['e'].'pro where shop_id="'.$shop['id'].'" group by c';
$cc=db($sql);
$m=g('m');
?>
<style>
pro_list_box{float:left;width:100%;height:100%;padding-left:120px}
right_in_box{padding-bottom:0px}
pro_c{position:absolute;width:120px;left:0;top:0;height:100%;padding-left:10px;padding-right:10px;border-right:1px solid #eee;}
pro_c a{float:left;width:100%;height:30px;line-height:30px;text-align:center;}
pro_item_box{float:left;width:100%;height:100%;overflow-y:auto;}
pro_in_item{float:left;width:50%;padding:5px}
pro_item_box .is_select{background:rgba(0,0,255,0.1);}
pro_c .select{font-weight:bold;}
</style>
<pro_list_box>
<pro_c>
<?php 
echo '<a class="'.(!$c?'select':'').'" onclick="pro_c($(this))" val="">全部</a>';
if($cc){
foreach($cc as $v){
if($v['c']){
echo '<a class="'.($c==$v['c']?'select':'').'" onclick="pro_c($(this))" val="'.$v['c'].'">'.$v['c'].'</a>';}
}
}
?>
</pro_c>

<pro_item_box>
<?php 
if($l){
foreach($l as $v){
echo '<pro_in_item >';
$img=get_img($v['img'],'_240');
echo '<pro_item class="pro_'.$v['id'].' " >';
echo '<pro_img style="background:url('.$img.') no-repeat center;background-size:cover;"></pro_img>';
echo '<input placeholder="商品名称" value="'.base64($v['title']).'" c="title" onchange="pro_change($(this))" i="'.$v['id'].'">';
echo '<input placeholder="价格" value="'.$v['price'].'" c="price" type="number" onchange="pro_change($(this))" i="'.$v['id'].'">';
echo '<input placeholder="原价" value="'.$v['old'].'" c="old" type="number" onchange="pro_change($(this))" i="'.$v['id'].'">';
echo '<input placeholder="库存" value="'.$v['total'].'" c="total" type="number" onchange="pro_change($(this))" i="'.$v['id'].'">';
echo '<index>
<a class="m b" onclick="'.$action.'" i="'.$v['id'].'" c="add">选择商品</a>
</index>';
echo '</pro_item>';
echo '</pro_in_item>';
}
}else{no_data('您还没有商品');}

?>
</pro_item_box>


</pro_list_box>

<script>
<?php if($m=='pro'){ ?>
$('pro_list pro_item').each(function(){
var id=$(this).attr('c');
$('pro_item_box .'+id).addClass('is_select');
})
<?php } ?>

function pro_c(o){
var val=o.attr('val');if(!val){val='';}
window.right_url='./hd_pro_list.php?c='+val;
right_reload();
}


</script>